package com.atguigu.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
//订单确认页面需要的数据

public class OrderConfirmVo {
    @Getter
    @Setter
    Map<Long,Boolean> stocks;
    //收货地址
    @Getter
    @Setter
List<MemberAddressVo> address;
//所有选中的购物项
@Getter
@Setter
    List<OrderItemVo>items;
    //发票信息 记录

    //优惠券信息
    @Getter
    @Setter
    Integer integration;

    //防重令牌
    @Getter
    @Setter
    String orderToken;
//    BigDecimal total;//总额

    public Integer getCount(){
        Integer i=0;
        if (!items.isEmpty()){
            for (OrderItemVo item : items) {
            i+=item.getCount();
            }
        }
        return i;
    }

    public BigDecimal getTotal() {
        BigDecimal sum=new BigDecimal(0);
        if (!items.isEmpty()){
            for (OrderItemVo item : items) {
//             sum+=sum.add(item.getPrice().multiply(new BigDecimal(item.getCount()));not like this
             sum=sum.add(item.getPrice().multiply(new BigDecimal(item.getCount())));
            }
        }
        return sum;
    }

//    BigDecimal payPrice;//应付金额

    public BigDecimal getPayPrice() {
        return getTotal();
    }
}
